package core;


import okhttp3.Response;

import java.io.IOException;

public class KrnResponse{
    private Response OKHTTPResponse;
    private String data;
    private int code;
    private Exception error;

    public KrnResponse(Response OKresponse){
        try {
            OKHTTPResponse = OKresponse;
            data = OKHTTPResponse.body().string();
            code = OKHTTPResponse.code();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public KrnResponse(Exception exception){
            OKHTTPResponse = null;
            data = exception.toString();
            error = exception;
    }


    public String data(){
        return data;
    }

    public int code(){
        return code;
    }

    public String header(String key){
        return OKHTTPResponse.header(key);
    }

    public String header(String key,String defaultvalue){

        return OKHTTPResponse.header(key, defaultvalue);
    }

    public boolean isSuccessful(){
        return OKHTTPResponse.isSuccessful();
    }

    public Response getOKHTTPResponse(){
            return OKHTTPResponse;
    }

    public String toString(){
        return data;
    }

}
